﻿#include "agreeapplicationdialog.h"
#include "ui_agreeapplicationdialog.h"

AgreeApplicationDialog::AgreeApplicationDialog(const QString &email,QWidget *parent) :
    QDialog(parent),
    email(email),
    ui(new Ui::AgreeApplicationDialog)
{
    ui->setupUi(this);
    {
        // 获取当前窗口标志
        Qt::WindowFlags flags = this->windowFlags();
        // 清除所有标志，然后重新设置需要的标志
        flags |= Qt::CustomizeWindowHint;          // 设置自定义窗口标志
        flags &= ~Qt::WindowCloseButtonHint;       // 清除关闭按钮标志
        flags &= ~Qt::WindowTitleHint;             // 清除标题栏标志
        flags &= ~Qt::WindowMinMaxButtonsHint;    // 清除最小化和最大化按钮标志

        // 设置修改后的标志集
        this->setWindowFlags(flags);
    }
    setAttribute(Qt::WA_DeleteOnClose);

    connect(ui->sure_BT,&QPushButton::clicked,[this](){
        emit agreeApplication(this->email,ui->note_LE->text());
        emit finished();
        this->close();
    });

    connect(ui->cancel_BT,&QPushButton::clicked,[this](){
        emit finished();
        this->close();
    });
}

AgreeApplicationDialog::~AgreeApplicationDialog()
{
    delete ui;
}

void AgreeApplicationDialog::mousePressEvent(QMouseEvent* event){
    if (event->button() == Qt::LeftButton) {
        isDragging = true;
        lastPos =event->pos(); // 鼠标按下时记录鼠标相对窗体的位置
    }
}
void AgreeApplicationDialog::mouseMoveEvent(QMouseEvent* event){
    if (isDragging&&event->buttons() & Qt::LeftButton) {
        // 移动窗口
        move(event->globalPos() - lastPos);//event->globalPos()记录窗体的原点在整个电脑窗口的位置
    }
}
void AgreeApplicationDialog::mouseReleaseEvent(QMouseEvent* event){
    if (event->button() == Qt::LeftButton && isDragging&&!isMaximized()) {
        isDragging = false;
    }
}
void AgreeApplicationDialog::setNoteName(const QString &notename){
    ui->note_LE->setText(notename);
}
